package com.qi.spzx.manager.controller;

import com.github.pagehelper.PageInfo;
import com.qi.spzx.manager.service.BrandService;
import com.qi.spzx.model.entity.product.Brand;
import com.qi.spzx.model.vo.common.Result;
import com.qi.spzx.model.vo.common.ResultCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description TODO
 * @Author dingchunlin
 * @Date 2024/2/23 15:01
 * @Version 1.0.0
 */
@RestController
@RequestMapping(value="/admin/product/brand")
public class BrandController {

    @Autowired
    private BrandService brandService;

    /**
     * 进行分页查询
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("/{page}/{limit}")
    public Result<PageInfo<Brand>> findByPage(@PathVariable Integer page, @PathVariable Integer limit) {
        PageInfo<Brand> pageInfo = brandService.findByPage(page, limit);
        return Result.build(pageInfo , ResultCodeEnum.SUCCESS) ;
    }

    /**
     * 进行品牌的保存
     * @param brand
     * @return
     */
    @PostMapping("/saveBrand")
    public Result save(@RequestBody Brand brand) {
        brandService.save(brand);
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }

    /**
     * 进行删除
     * @param id
     * @return
     */
    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable("id") Long id) {
        brandService.deleteById(id);
        return Result.build(null , ResultCodeEnum.SUCCESS);
    }

    /**
     * 进行品牌数据的修改
     * @param brand
     * @return
     */
    @PutMapping("/updateById")
    public Result updateById(@RequestBody Brand brand) {
        brandService.updateById(brand);
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }

    /**
     * 查询全部品牌
     * @return
     */
    @GetMapping("/findAll")
    public Result findAll() {
        List<Brand> brandList = brandService.findAll();
        return Result.build(brandList , ResultCodeEnum.SUCCESS);
    }


}
